
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>kafka模块 · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="scheduler.html" />
    
    
    <link rel="prev" href="cache.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    概要
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1.1" data-path="../architecture.html">
            
                <a href="../architecture.html">
            
                    
                    总体架构
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../quick-start.html">
            
                <a href="../quick-start.html">
            
                    
                    快速开始
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="../quickstart/confcenter.html">
            
                <a href="../quickstart/confcenter.html">
            
                    
                    配置中心
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="../quickstart/oneplatform.html">
            
                <a href="../quickstart/oneplatform.html">
            
                    
                    oneplatform企业级开发平台
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3" data-path="../quickstart/passport.html">
            
                <a href="../quickstart/passport.html">
            
                    
                    统一认证平台
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../jeesuite-lib.html">
            
                <a href="../jeesuite-lib.html">
            
                    
                    jeesuite-libs使用文档
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="common.html">
            
                <a href="common.html">
            
                    
                    common模块
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="common2.html">
            
                <a href="common2.html">
            
                    
                    common2模块
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="spring.html">
            
                <a href="spring.html">
            
                    
                    Spring模块
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.4" data-path="mybatis.html">
            
                <a href="mybatis.html">
            
                    
                    mybatis模块
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.5" data-path="cache.html">
            
                <a href="cache.html">
            
                    
                    cache模块
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.3.6" data-path="kafka.html">
            
                <a href="kafka.html">
            
                    
                    kafka模块
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.7" data-path="scheduler.html">
            
                <a href="scheduler.html">
            
                    
                    scheduler模块
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.8" data-path="filesystem.html">
            
                <a href="filesystem.html">
            
                    
                    filesystem模块
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.9" data-path="rest.html">
            
                <a href="rest.html">
            
                    
                    restAPI模块
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.10" data-path="springboot-starter.html">
            
                <a href="springboot-starter.html">
            
                    
                    springboot-starter模块
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../integration.html">
            
                <a href="../integration.html">
            
                    
                    系统集成
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="../integration/confcenter.html">
            
                <a href="../integration/confcenter.html">
            
                    
                    集成配置中心
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="../integration/passport.html">
            
                <a href="../integration/passport.html">
            
                    
                    集成认证中心
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="../base-env-install.html">
            
                <a href="../base-env-install.html">
            
                    
                    附：基础环境搭建
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >kafka模块</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h3 id="&#x529F;&#x80FD;&#x8BF4;&#x660E;">&#x529F;&#x80FD;&#x8BF4;&#x660E;</h3>
<ul>
<li>&#x57FA;&#x4E8E;spring&#x5C01;&#x88C5;&#x7B80;&#x5316;&#x914D;&#x7F6E;&#x548C;&#x8C03;&#x7528;&#x65B9;&#x5F0F;</li>
<li>&#x57FA;&#x4E8E;&#x914D;&#x7F6E;&#x65B0;&#x65E7;&#x4E24;&#x7248;Consumer API&#x517C;&#x5BB9;&#x652F;&#x6301;</li>
<li>&#x652F;&#x6301;&#x4E8C;&#x9636;&#x6BB5;&#x5904;&#x7406;&#xFF0C;&#x5373;&#xFF1A;fetch&#x7EBF;&#x7A0B;&#x540C;&#x6B65;&#x5904;&#x7406;&#x548C;process&#x7EBF;&#x7A0B;&#x5F02;&#x6B65;&#x5904;&#x7406;</li>
<li>&#x6D88;&#x8D39;&#x6210;&#x529F;&#x4E1A;&#x52A1;&#x5904;&#x7406;&#x5931;&#x8D25;&#x81EA;&#x52A8;&#x91CD;&#x8BD5;&#x6216;&#x81EA;&#x5B9A;&#x4E49;&#x91CD;&#x8BD5;&#x652F;&#x6301;</li>
<li>process&#x7EBF;&#x7A0B;&#x6C60;&#x91C7;&#x7528;<code>LinkedTransferQueue</code>&#xFF0C;&#x652F;&#x6301;&#x7EBF;&#x7A0B;&#x56DE;&#x6536;&#x548C;&#x961F;&#x5217;&#x5927;&#x5C0F;&#x9650;&#x5236;&#xFF0C;&#x786E;&#x4FDD;&#x7CFB;&#x7EDF;&#x5D29;&#x6E83;&#x7B49;&#x4E0D;&#x4F1A;&#x6709;&#x6570;&#x636E;&#x4E22;&#x5931;&#x3002;</li>
<li>&#x652F;&#x6301;&#x7279;&#x6B8A;&#x573A;&#x666F;&#x53D1;&#x9001;&#x6709;&#x72B6;&#x6001;&#x7684;&#x6D88;&#x606F;&#xFF08;&#x5982;&#xFF1A;&#x540C;&#x4E00;&#x4E2A;&#x7528;&#x6237;&#x7684;&#x6D88;&#x606F;&#x5168;&#x90E8;&#x7531;&#x67D0;&#x4E00;&#x4E2A;&#x6D88;&#x8D39;&#x8282;&#x70B9;&#x5904;&#x7406;&#xFF09;</li>
<li>producer&#x3001;consumer&#x7AEF;&#x76D1;&#x63A7;&#x6570;&#x636E;&#x91C7;&#x96C6;&#xFF0C;&#x7531;&#xFF08;<a href="http://git.oschina.net/vakinge/jeesuite-admin" target="_blank">jeesuite-admin</a>&#xFF09;&#x8F93;&#x51FA;</li>
<li>&#x652F;&#x6301;producer&#x5EF6;&#x8FDF;&#x91CD;&#x8BD5;</li>
<li>&#x652F;&#x6301;offset&#x6301;&#x4E45;&#x5316;&#xFF0C;&#x5E94;&#x7528;&#x542F;&#x52A8;&#x81EA;&#x52A8;&#x6062;&#x590D;&#x6307;&#x5B9A;&#x7684;offset</li>
</ul>
<h3 id="&#x4F7F;&#x7528;&#x8BF4;&#x660E;">&#x4F7F;&#x7528;&#x8BF4;&#x660E;</h3>
<h4 id="&#x6DFB;&#x52A0;&#x4F9D;&#x8D56;">&#x6DFB;&#x52A0;&#x4F9D;&#x8D56;</h4>
<pre><code>&lt;dependency&gt;
    &lt;groupId&gt;com.jeesuite&lt;/groupId&gt;
    &lt;artifactId&gt;jeesuite-kafka&lt;/artifactId&gt;
    &lt;version&gt;[&#x6700;&#x65B0;&#x7248;&#x672C;]&lt;/version&gt;
&lt;/dependency&gt;
</code></pre><h4 id="&#x5F00;&#x53D1;&#x4E00;&#x4E2A;producer">&#x5F00;&#x53D1;&#x4E00;&#x4E2A;producer</h4>
<h6 id="&#x9996;&#x5148;&#x5728;spring&#x6CE8;&#x518C;&#xFF0C;&#x6DFB;&#x52A0;&#x4EE5;&#x4E0B;&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x5373;&#x53EF;">&#x9996;&#x5148;&#x5728;spring&#x6CE8;&#x518C;&#xFF0C;&#x6DFB;&#x52A0;&#x4EE5;&#x4E0B;&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x5373;&#x53EF;</h6>
<pre><code>    &lt;bean id=&quot;topicProducerProvider&quot; class=&quot;com.jeesuite.kafka.spring.TopicProducerSpringProvider&quot;&gt;
        &lt;!-- &#x9ED8;&#x8BA4;&#x662F;&#x5426;&#x5F02;&#x6B65;&#x53D1;&#x9001; --&gt;
        &lt;property name=&quot;defaultAsynSend&quot; value=&quot;true&quot; /&gt;
        &lt;!-- &#x6807;&#x8BC6;&#x540C;&#x4E00;&#x96C6;&#x7FA4;&#xFF0C;&#x76D1;&#x63A7;&#x9700;&#x8981; --&gt;
        &lt;property name=&quot;producerGroup&quot; value=&quot;demo&quot; /&gt;
        &lt;!-- &#x914D;&#x7F6E;zkServers&#x7528;&#x4E8E;&#x76D1;&#x63A7;&#x4FE1;&#x606F;&#x540C;&#x6B65;&#xFF0C;&#x4E0D;&#x914D;&#x7F6E;&#x5219;&#x4E0D;&#x5F00;&#x542F;producer&#x76D1;&#x63A7; --&gt;
        &lt;property name=&quot;monitorZkServers&quot; value=&quot;127.0.0.1:2181&quot; /&gt;
        &lt;!-- 
          &#x5EF6;&#x8FDF;&#x91CD;&#x8BD5;&#x6B21;&#x6570;&#xFF0C;&#x9ED8;&#x8BA4;&#x4E3A;3&#x3002; 
          &#x5EF6;&#x8FDF;&#x91CD;&#x8BD5;&#x4E0E;kafka&#x81EA;&#x8EAB;&#x91CD;&#x8BD5;&#x4E0D;&#x540C;&#x3002;&#x5982;&#x679C;&#x5F00;&#x542F;&#x4E86;&#x5EF6;&#x65F6;&#x91CD;&#x8BD5;&#x3001;kafka&#x91CD;&#x8BD5;retries&#x5EFA;&#x8BAE;&#x8BBE;&#x7F6E;&#x4E3A;1&#x6216;&#x8005;0
          kafka&#x81EA;&#x8EAB;&#x91CD;&#x8BD5;&#xFF1A;&#x53D1;&#x9001;&#x5931;&#x8D25;&#x8FDE;&#x7EED;&#x91CD;&#x8BD5;
          &#x5EF6;&#x8FDF;&#x91CD;&#x8BD5;&#xFF1A;&#x901A;&#x8FC7;&#x5F02;&#x6B65;&#x7EBF;&#x7A0B;&#x9636;&#x68AF;&#x6027;&#x91CD;&#x8BD5;&#x3002;&#x5982;&#xFF1A;30&#x79D2;&#x540E;&#x91CD;&#x8BD5;&#x7B2C;&#x4E00;&#x6B21;&#x3001;60&#x79D2;&#x540E;&#x91CD;&#x8BD5;&#x7B2C;&#x4E8C;&#x6B21;
          &#x5EF6;&#x8FDF;&#x91CD;&#x8BD5;&#x53EA;&#x9488;&#x5BF9;&#x5F02;&#x6B65;&#x53D1;&#x9001;&#x6A21;&#x5F0F;&#x3002;
        --&gt;
        &lt;property name=&quot;delayRetries&quot; value=&quot;3&quot; /&gt;
        &lt;property name=&quot;configs&quot;&gt;
            &lt;!-- &#x4EE5;&#x4E0B;&#x53C2;&#x6570;&#x53C2;&#x8003;:http://kafka.apache.org/documentation.html#producerconfigs --&gt;
            &lt;props&gt;
                &lt;prop key=&quot;bootstrap.servers&quot; &gt;${kafka.servers}&lt;/prop&gt;
                &lt;prop key=&quot;acks&quot;&gt;1&lt;/prop&gt;
                &lt;prop key=&quot;retries&quot;&gt;1&lt;/prop&gt;
                &lt;!-- &lt;prop key=&quot;value.serializer&quot;&gt;org.apache.kafka.common.serialization.StringSerializer&lt;/prop&gt; --&gt;
            &lt;/props&gt;
        &lt;/property&gt;
    &lt;/bean&gt;
</code></pre><h6 id="&#x53D1;&#x9001;&#x4E00;&#x6761;&#x6D88;&#x606F;">&#x53D1;&#x9001;&#x4E00;&#x6761;&#x6D88;&#x606F;</h6>
<pre><code class="lang-java"><span class="hljs-meta">@Autowired</span>
<span class="hljs-keyword">private</span> TopicProducerSpringProvider topicProducer;

<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">testPublish</span><span class="hljs-params">()</span> </span>{
    <span class="hljs-comment">//&#x9ED8;&#x8BA4;&#x6A21;&#x5F0F;&#xFF08;&#x5F02;&#x6B65;/ &#x540C;&#x6B65;&#xFF09;&#x53D1;&#x9001;</span>
    topicProducer.publish(<span class="hljs-string">&quot;demo-topic&quot;</span>, <span class="hljs-keyword">new</span> DefaultMessage(<span class="hljs-string">&quot;hello,man&quot;</span>));
    <span class="hljs-comment">//&#x5F02;&#x6B65;&#x53D1;&#x9001;</span>
    topicProducer.publish(<span class="hljs-string">&quot;demo-topic&quot;</span>, <span class="hljs-keyword">new</span> DefaultMessage(<span class="hljs-string">&quot;hello,man&quot;</span>),<span class="hljs-keyword">true</span>);
    <span class="hljs-comment">//&#x53D1;&#x9001;&#x672A;&#x5305;&#x88C5;&#x7684;&#x6D88;&#x606F;&#x4F53;&#xFF08;&#x517C;&#x5BB9;&#x5F02;&#x6784;&#x7684;consumer&#x7AEF;&#xFF09;</span>
    topicProducer.publishNoWrapperMessage(<span class="hljs-string">&quot;demo-topic&quot;</span>, JsonUtils.toJson(user),<span class="hljs-keyword">true</span>);
}
</code></pre>
<h6 id="&#x5173;&#x4E8E;defaultmessage">&#x5173;&#x4E8E;DefaultMessage</h6>
<pre><code class="lang-java">DefaultMessage msg = <span class="hljs-keyword">new</span> DefaultMessage(<span class="hljs-string">&quot;hello,man&quot;</span>)
                    .header(<span class="hljs-string">&quot;headerkey1&quot;</span>, <span class="hljs-string">&quot;headerval1&quot;</span>)<span class="hljs-comment">//&#x5199;&#x5165;header&#x4FE1;&#x606F;</span>
                    .header(<span class="hljs-string">&quot;headerkey1&quot;</span>, <span class="hljs-string">&quot;headerval1&quot;</span>)<span class="hljs-comment">//&#x5199;&#x5165;header&#x4FE1;&#x606F;</span>
                    .partitionFactor(<span class="hljs-number">1000</span>); <span class="hljs-comment">//&#x5206;&#x533A;&#x56E0;&#x5B50;&#xFF0C;&#x8B6C;&#x5982;userId&#xFF1D;1000&#x7684;&#x5C06;&#x53D1;&#x9001;&#x5230;&#x540C;&#x4E00;&#x5206;&#x533A;&#x3001;&#x4ECE;&#x800C;&#x53D1;&#x9001;&#x5230;&#x6D88;&#x8D39;&#x8005;&#x7684;&#x540C;&#x4E00;&#x8282;&#x70B9;(&#x6709;&#x72B6;&#x6001;)</span>
</code></pre>
<h4 id="&#x5F00;&#x53D1;&#x4E00;&#x4E2A;consumer">&#x5F00;&#x53D1;&#x4E00;&#x4E2A;consumer</h4>
<h6 id="&#x9996;&#x5148;&#x5728;spring&#x6CE8;&#x518C;&#xFF0C;&#x6DFB;&#x52A0;&#x4EE5;&#x4E0B;&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x5373;&#x53EF;">&#x9996;&#x5148;&#x5728;spring&#x6CE8;&#x518C;&#xFF0C;&#x6DFB;&#x52A0;&#x4EE5;&#x4E0B;&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x5373;&#x53EF;</h6>
<pre><code>&lt;bean  id=&quot;topicConsumerProvider&quot; class=&quot;com.jeesuite.kafka.spring.TopicConsumerSpringProvider&quot;&gt;
        &lt;!-- &#x5982;&#x679C;&#x4E3A;false&#x542F;&#x52A8;&#x65F6;&#x5C06;&#x963B;&#x585E;&#x4E3B;&#x7EBF;&#x7A0B;&#xFF0C;&#x5982;zk&#x8FDE;&#x63A5;&#x8D85;&#x65F6;&#x5C31;&#x62A5;&#x9519; --&gt;
        &lt;property name=&quot;independent&quot; value=&quot;false&quot; /&gt;
        &lt;!-- &#x4F7F;&#x7528;&#x65B0;&#x7248;API&#x5F00;&#x5173;,&#x65B0;&#x7248;&#x672A;&#x5728;&#x7EBF;&#x4E0A;&#x8FD0;&#x884C;&#x8FC7;&#xFF0C;&#x7EBF;&#x4E0A;&#x6682;&#x7528;&#x8001;&#x7248;API&#x5427; --&gt;
        &lt;property name=&quot;useNewAPI&quot; value=&quot;false&quot; /&gt;
        &lt;!-- &#x9ED8;&#x8BA4;&#x6700;&#x5927;&#x5904;&#x7406;&#x7EBF;&#x7A0B;&#xFF0C;&#x53EF;&#x4EE5;&#x914D;&#x7F6E;&#x5927;&#x4E00;&#x4E0B;&#x7A7A;&#x95F2;&#x4F1A;&#x81EA;&#x52A8;&#x56DE;&#x6536; --&gt;
        &lt;property name=&quot;processThreads&quot; value=&quot;100&quot; /&gt;
        &lt;!--&#x81EA;&#x5B9A;&#x4E49;offset&#x8BB0;&#x5F55;&#x5668;&#xFF08;&#x53EF;&#x9009;&#xFF09;--&gt;
        &lt;property name=&quot;offsetLogHanlder&quot;&gt;
           &lt;bean class=&quot;com.jeesuite.test.MysqlOffsetLogHanlder&quot; /&gt;
        &lt;/property&gt;
        &lt;property name=&quot;configs&quot;&gt;
            &lt;!--&#x53C2;&#x8003; http://kafka.apache.org/documentation.html#newconsumerconfigs --&gt;
            &lt;props&gt;
               &lt;!-- &#x8001;&#x7248; consumerAPI &#x624D;&#x9700;&#x8981;zookeeper.connect --&gt;
               &lt;prop key=&quot;zookeeper.connect&quot; &gt;${kafka.zkServers}&lt;/prop&gt;
                &lt;prop key=&quot;bootstrap.servers&quot; &gt;${kafka.servers}&lt;/prop&gt;
                &lt;!-- &#x540C;&#x4E00;&#x4E2A;&#x7EC4;&#x5BF9;&#x540C;&#x4E00;&#x4E2A;&#x6D88;&#x606F;&#x53EA;&#x4F1A;&#x6D88;&#x8D39;&#x4E00;&#x6B21;&#xFF0C;&#x6240;&#x4EE5;&#x4E0D;&#x540C;&#x4E1A;&#x52A1;&#x4F7F;&#x7528;&#x4E0D;&#x540C;&#x7684;group.id --&gt;
                &lt;prop key=&quot;group.id&quot;&gt;kafka-demo2&lt;/prop&gt;
                &lt;prop key=&quot;enable.auto.commit&quot;&gt;true&lt;/prop&gt;
                &lt;!-- old api&#x53EF;&#x9009;&#x503C;&#xFF1A;smallest&#xFF0C;largest&#xFF1B; &#x65B0;&#x7248;api&#x53EF;&#x9009;&#x503C;&#xFF1A;earliest&#xFF0C;largest --&gt;
                &lt;prop key=&quot;auto.offset.reset&quot;&gt;smallest&lt;/prop&gt;
                &lt;!-- 131072 = 128kb --&gt;
                &lt;prop key=&quot;max.partition.fetch.bytes&quot;&gt;131072&lt;/prop&gt;
            &lt;/props&gt;
        &lt;/property&gt;
        &lt;property name=&quot;topicHandlers&quot; &gt;
            &lt;map&gt;
              &lt;!-- &#x6307;&#x5B9A;&#x6D88;&#x606F;&#x76D1;&#x542C;&#x5668; --&gt;
              &lt;entry key=&quot;demo-topic&quot;&gt;
                 &lt;bean class=&quot;com.jeesuite.test.DemoMessageHandler&quot; /&gt;
              &lt;/entry&gt;
              &lt;entry key=&quot;demo2-topic&quot;&gt;
                 &lt;bean class=&quot;com.jeesuite.test.Demo2MessageHandler&quot; /&gt;
              &lt;/entry&gt;
            &lt;/map&gt;
        &lt;/property&gt;
    &lt;/bean&gt;
</code></pre><h6 id="&#x7F16;&#x5199;&#x4E00;&#x4E2A;&#x5BF9;&#x5E94;&#x7684;&#x6D88;&#x606F;&#x5904;&#x7406;&#x5668;">&#x7F16;&#x5199;&#x4E00;&#x4E2A;&#x5BF9;&#x5E94;&#x7684;&#x6D88;&#x606F;&#x5904;&#x7406;&#x5668;</h6>
<pre><code class="lang-java"><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">DemoMessageHandler</span> <span class="hljs-keyword">implements</span> <span class="hljs-title">MessageHandler</span> </span>{

    <span class="hljs-meta">@Override</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">p1Process</span><span class="hljs-params">(DefaultMessage message)</span> </span>{
        <span class="hljs-comment">//&#x7B2C;&#x4E00;&#x9636;&#x6BB5;&#x5904;&#x7406;&#x662F;&#x540C;&#x6B65;&#x5904;&#x7406;&#xFF0C;&#x5373;&#x5728;fetch&#x7EBF;&#x7A0B;&#x5904;&#x7406;</span>
    }

    <span class="hljs-meta">@Override</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">p2Process</span><span class="hljs-params">(DefaultMessage message)</span> </span>{
        <span class="hljs-comment">//&#x7B2C;&#x4E8C;&#x9636;&#x6BB5;&#x5904;&#x7406;&#x662F;&#x5F02;&#x6B65;&#x5904;&#x7406;&#xFF0C;&#x5728;&#x5904;&#x7406;&#x7EBF;&#x7A0B;&#x6C60;&#x6392;&#x961F;&#x5904;&#x7406;</span>
        Serializable body = message.getBody();
        System.out.println(<span class="hljs-string">&quot;DemoMessageHandler process message:&quot;</span> + body);
        <span class="hljs-keyword">try</span> {Thread.sleep(<span class="hljs-number">100</span>);} <span class="hljs-keyword">catch</span> (Exception e) {}
    }


    <span class="hljs-meta">@Override</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">boolean</span> <span class="hljs-title">onProcessError</span><span class="hljs-params">(DefaultMessage message)</span> </span>{
        System.out.println(<span class="hljs-string">&quot;ignore error message : &quot;</span>+message);
        <span class="hljs-keyword">return</span> <span class="hljs-keyword">true</span>;
    }

}
</code></pre>
<p>MessageHandler&#x7684;&#x4E00;&#x4E9B;&#x8BF4;&#x660E;</p>
<ul>
<li>&#x4E24;&#x9636;&#x6BB5;&#x5904;&#x7406;&#x7684;&#x540C;&#x4E00;&#x4EFD;&#x6570;&#x636E;&#x3001;&#x4E00;&#x822C;&#x60C5;&#x51B5;&#x7B2C;&#x4E8C;&#x9636;&#x6BB5;&#x5904;&#x7406;&#x5373;&#x53EF;&#x3002;</li>
<li>&#x5982;&#x679C;&#x8981;&#x89E6;&#x53D1;&#x91CD;&#x8BD5;&#x673A;&#x5236;&#x8BF7;&#x4E0D;&#x8981;try catch&#x5F02;&#x5E38;</li>
<li>onProcessError &#x8FD4;&#x56DE;true&#x8868;&#x793A;&#x4E1A;&#x52A1;&#x81EA;&#x8EAB;&#x5904;&#x7406;&#x9519;&#x8BEF;&#xFF0C;&#x5426;&#x5219;&#x6846;&#x67B6;&#x4F1A;&#x6BCF;30&#x79D2;&#x91CD;&#x65B0;&#x6267;&#x884C;&#x4E00;&#x6B21;&#xFF0C;&#x6700;&#x591A;&#x91CD;&#x8BD5;3&#x6B21;</li>
</ul>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="cache.html" class="navigation navigation-prev " aria-label="Previous page: cache模块">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="scheduler.html" class="navigation navigation-next " aria-label="Next page: scheduler模块">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"kafka模块","level":"1.3.6","depth":2,"next":{"title":"scheduler模块","level":"1.3.7","depth":2,"path":"jeesuite-libs/scheduler.md","ref":"jeesuite-libs/scheduler.md","articles":[]},"previous":{"title":"cache模块","level":"1.3.5","depth":2,"path":"jeesuite-libs/cache.md","ref":"jeesuite-libs/cache.md","articles":[]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":[],"pluginsConfig":{"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"jeesuite-libs/kafka.md","mtime":"2017-09-11T08:28:11.000Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2018-05-04T10:30:11.187Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

